package practice_3_2;
//求斐波那契数列的第n项。(迭代实现)
public class Fibonacci {
    public static void main(String[] args) {
        int n = 1000;
        int f = fib(n);
        System.out.printf("fib(%d) = %d", n, f);
    }
    public static int fib(int n){
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        if(n <= 2){
            return 1;
        }
        for(int i = 3; i <= n; i++){
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
}
